#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>

#include "D3D Base.h"
#include "cTools.h"
#include "cMenu.h"

BOOL WINAPI DllMain( HMODULE hModule, DWORD  dwCallType, LPVOID lpReserved );

//#pragma comment( linker,"/merge:.text=.text /merge:.data=.data /merge:.rdata=.rdata" ) 
//#pragma comment( linker," /BASE:0x72800000 /ALIGN:0x200" )
#pragma comment(lib, "d3dx9.lib")

pPresent oPresent;
pReset oReset;
pDrawIndexedPrimitive oDrawIndexedPrimitive;
pEndScene oEndScene;
pSetStreamSource oSetStreamSource;
pDrawPrimitive oDrawPrimitive;
pSetRenderState oSetRenderState;

UINT MyStride;
int x = 0;
int qq = x+ ++4;
D3DCOLOR dcBorderColor, dcBodyColor;

ID3DXFont* pFont, *pFontTitle, *pPresentFont;

#define FREE_MEM(i) ( (unsigned long)pGetModuleHandle("d3d9.dll") + 0x1000 - ( i? i*0x20:0x20 ) ) 
#define D3DCOLOR_RED D3DCOLOR_ARGB(100,255,69,0)

#define DIP_PROLOGUE_MACRO _asm{push ebp} _asm{mov ebp, esp} _asm{NOP} _asm{add ebp, 0x40} _asm{pushad} //40 old
#define DIP_EPILOGUE_MACRO  _asm{popad} _asm{sub ebp, 0x40} _asm{mov esp, ebp} _asm{pop ebp} _asm{xor ebx, ebx} _asm{ jmp [oDrawIndexedPrimitive] }

#define ENDSCENE_PROLOGUE_MACRO _asm{push ebp} _asm{mov ebp, esp} _asm{NOP} _asm{add ebp, 0x34} _asm{pushad} //40 old
#define ENDSCENE_EPILOGUE_MACRO  _asm{popad} _asm{sub ebp, 0x34} _asm{mov esp, ebp} _asm{pop ebp} _asm{xor ebx, ebx} _asm{ jmp [oEndScene] }

#define RESET_PROLOGUE_MACRO _asm{push ebp} _asm{mov ebp, esp} _asm{NOP} _asm{add ebp, 0x150} _asm{pushad} //40 old
#define RESET_EPILOGUE_MACRO  _asm{popad} _asm{sub ebp, 0x150} _asm{mov esp, ebp} _asm{pop ebp} _asm{xor esi, esi} _asm{ jmp [oReset] }

#define EFFECTS 24 
#define GROUND 28 
#define WEAPON 32
#define PLAYER 36
#define WALLS 40
#define VEHICLES 44

cTools _cTools, *pTools = &_cTools;
cMenu Menu, *pMenu = &Menu;

DWORD dwLightCur1, dwLightCur2;
LPDIRECT3DTEXTURE9 Red, White, Yellow, Black, Green, Blue, Purple, Orange, Cur1, Cur2, ThingsColor;

short PlayerFolder = 0;
short Stamina = 0;
short Speed = 0;
short Spread = 0;
short RollSpeed = 0;
short Fahr = 0;
short Scope = 0;
short Spawn = 0;
short CQCSpawn = 0;

short D3DFolder = 0;
short Chams = 0;
short ChamsColor1 = 0;
short ChamsColor2 = 0;
short WireFrame = 0;
short Fog = 0;
short FogColor = 0;
short ColoredThings = 0;
short ColoredThingsColors = 0;
short Asus = 0;

short SettingsFolder = 0;
short BorderColor = 0;
short BodyColor = 0;
short BodyTransparent = 0;
short BorderSize = 0;


VOID WINAPI Items() 
{
	pMenu->AddItem("D3D", true, &D3DFolder);
	pMenu->AddItem("Chams", false, &Chams, "Off|Solid|WireFrame|Point|Light|Ghost|Cube");
	//pMenu->AddItem("WireFrame", false, &WireFrame, "Off|Player|Vehicles|Ground|Walls|Weapons");
	pMenu->AddItem("Chams Color 1/2", false, &ChamsColor1, "Off|Red|Blue|Green|Yellow|Black|White|Orange|Purple");
	pMenu->AddItem("Chams Color 2/2", false, &ChamsColor2, "Off|Red|Blue|Green|Yellow|Black|White|Orange|Purple");
	pMenu->AddItem("No Fog", false, &Fog);
	//pMenu->AddItem("Fog Color", false, &FogColor, "Off|Red|Blue|Green|Yellow|Black|White|Orange|Purple");
	pMenu->AddItem("Colored Things", false, &ColoredThings, "Off|Walls|Ground|Weapons|Vehicles");
	pMenu->AddItem("CT Color", false, &ColoredThingsColors, "Off|Red|Blue|Green|Yellow|Black|White|Orange|Purple");
	pMenu->AddItem("Asus Wallhack", false, &Asus);
	//pMenu->AddItem("Player", true, &PlayerFolder);
	//pMenu->AddItem("Stamina", false, &Stamina);
	//pMenu->AddItem("No Spread", false, &Spread,"Off|0%|10%|20%|30%|40%|50%|60%|70%|80%|90%|100%");
	//pMenu->AddItem("Speed", false, &Speed, "Off|1.0|1.2|1.5|1.7|2.0|5.0|10.0");
	//pMenu->AddItem("Roll Speed", false, &RollSpeed, "Off|1.0|1.2|1.5|1.7|2.0|5.0|10.0");
	//pMenu->AddItem("Fast F/A/H/R", false, &Fahr);
	//pMenu->AddItem("Scope", false, &Scope);
	//pMenu->AddItem("Fast Spawn", false, &Spawn);
	//pMenu->AddItem("Fast CQC Spawn", false, &CQCSpawn);

	pMenu->AddItem("Settings", true, &SettingsFolder);
	pMenu->AddItem("Border Color", false, &BorderColor, "Off|Red|Blue|Green|Yellow|Black|White|Orange|Purple");
	pMenu->AddItem("Border Size", false, &BorderSize, "Off|5|4|3|2|1");
	pMenu->AddItem("Body Color", false, &BodyColor, "Off|Red|Blue|Green|Yellow|Black|White|Orange|Purple");
	pMenu->AddItem("Body Transparent", false, &BodyTransparent, "Off|100%|90%|80%|70%|60%|50%|40%|30%|20%|10%|0%");
}

HRESULT WINAPI hkReset (LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters) 
{
	//RESET_PROLOGUE_MACRO
	__asm NOP;
	/*if(pFont){
		pFont->OnLostDevice();
		pFontTitle->OnLostDevice();
	}*/
	static HRESULT hRet;
	 hRet = oReset(pDevice, pPresentationParameters);
	static bool var = true;
	
	/*if(var){
		 hRet = oReset(pDevice, pPresentationParameters);
		var = false;
	}var = true;*/

	if(hRet == D3D_OK){
		if(pFont){
			pFont->OnResetDevice();
			pFontTitle->OnResetDevice();
		}
	}
	//RESET_EPILOGUE_MACRO
	return hRet;
}

HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 pDevice)
 {
	__asm NOP;
	//ENDSCENE_PROLOGUE_MACRO
	HRESULT hRet = oEndScene(pDevice);

	static bool bInit = false, bMenu = false, blol = false;
	if(!bInit){
		pTools->GenerateTexture(pDevice, &Red,		D3DCOLOR_ARGB (255, 255,   0,    0 ));
		pTools->GenerateTexture(pDevice, &Yellow,	D3DCOLOR_ARGB (255, 255, 255,    0 ));
		pTools->GenerateTexture(pDevice, &Green,	D3DCOLOR_ARGB (255,   0, 255,    0 ));
		pTools->GenerateTexture(pDevice, &Blue,		D3DCOLOR_ARGB (255,   0,   0,  255 ));
		pTools->GenerateTexture(pDevice, &Purple,	D3DCOLOR_ARGB (255, 102,   0,  153 ));
		pTools->GenerateTexture(pDevice, &Orange,	D3DCOLOR_ARGB (255, 255, 165,    0 ));
		pTools->GenerateTexture(pDevice, &Black,	D3DCOLOR_ARGB (255, 0 ,   0 ,   0 ));
		pTools->GenerateTexture(pDevice, &White,	D3DCOLOR_ARGB (255, 255, 255 , 255 ));
		pTools->GenerateTexture(pDevice, &Black, 	D3DCOLOR_ARGB (255, 0, 0, 0 ));

		D3DXCreateFontA( pDevice, 16, 0,520 , 0, FALSE,ANSI_CHARSET, OUT_TT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Orator Std", &pFont);
		D3DXCreateFontA( pDevice, 16, 0,700 , 0, FALSE,ANSI_CHARSET, OUT_TT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Orator Std", &pFontTitle);
		bInit = true;
	}
	
	if(GetAsyncKeyState(VK_HOME) &1)
		bMenu = !bMenu;
		
	if(bMenu){
		//pMenu->DrawTxt(650, 640, D3DCOLOR_RED, pFont, pTools->GetFrameRate( )); 
		pMenu->DrawMenu(pDevice); 
	}
	//ENDSCENE_EPILOGUE_MACRO
	return hRet;
 }
	//pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVDESTCOLOR);
	//pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_INVSRCALPHA);
	//pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
__declspec(naked)HRESULT WINAPI hkDrawIndexedPrimitive ( LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) // 4FDD8840
{
	DIP_PROLOGUE_MACRO
	
	IDirect3DVertexBuffer9 *pStreamData;

    UINT pOffset;
    if (pDevice->GetStreamSource(0, &pStreamData, &pOffset, &MyStride) == D3D_OK)
			 pStreamData->Release();

	 static bool var = true;
	 static bool bInit = false;

	 //pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_WIREFRAME);

	if(var){
		switch(Chams){
		case 0:
			break;
		case 1: // solid 
			if(MyStride == PLAYER || MyStride == WEAPON){ 

				pDevice->SetRenderState(D3DRS_ZENABLE,false); 
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_SOLID);
				pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVDESTCOLOR);
				pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
				if(ChamsColor1)
					pDevice->SetTexture(NULL, Cur1);
				
				var = false;
				pDevice->DrawIndexedPrimitive(PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
				pDevice->SetRenderState(D3DRS_ZENABLE, true);
				pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVDESTCOLOR);

				pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
				if(ChamsColor2)
					pDevice->SetTexture(NULL, Cur2);
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_SOLID);

			}break;

		case 2: // wireframe
			if(MyStride == PLAYER || MyStride == WEAPON){ 

				pDevice->SetRenderState(D3DRS_ZENABLE,false); 
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_WIREFRAME);

				if(ChamsColor1)
					pDevice->SetTexture(NULL, Cur1);
				
				var = false;
				pDevice->DrawIndexedPrimitive(PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
				pDevice->SetRenderState(D3DRS_ZENABLE, true);

				if(ChamsColor2)
					pDevice->SetTexture(NULL, Cur2);
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_WIREFRAME);
			}break;

		case 3: //point
			if(MyStride == PLAYER || MyStride == WEAPON){ 

				pDevice->SetRenderState(D3DRS_ZENABLE,false); 
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_POINT);
				if(ChamsColor1)
					pDevice->SetTexture(NULL, Cur1);
				
				var = false;
				pDevice->DrawIndexedPrimitive(PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
				pDevice->SetRenderState(D3DRS_ZENABLE, true);
				if(ChamsColor2)
					pDevice->SetTexture(NULL, Cur2);
				 // Red|Blue|Green|Yellow|Black|White

				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_POINT);
			}break;
		case 4:// light
			if(MyStride == PLAYER || MyStride == WEAPON){ 
				pDevice->SetRenderState(D3DRS_ZENABLE,false); 
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_SOLID);
				
				if(ChamsColor1)
					pDevice->SetRenderState(D3DRS_AMBIENT, dwLightCur1);
				var = false;
				pDevice->DrawIndexedPrimitive(PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
				pDevice->SetRenderState(D3DRS_ZENABLE, true);
				if(ChamsColor2)
					pDevice->SetRenderState(D3DRS_AMBIENT, dwLightCur2);
				 // Red|Blue|Green|Yellow|Black|White
				
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_SOLID);
			}break;
		case 5:
			if(MyStride == PLAYER || MyStride == WEAPON){ 
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_SOLID);
				if(ChamsColor1)
					pDevice->SetRenderState(D3DRS_AMBIENT, dwLightCur1);
								pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVDESTCOLOR);
				//pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_INVSRCALPHA);
				pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
				pDevice->SetRenderState(D3DRS_ZENABLE,false); 
				var = false;
				pDevice->DrawIndexedPrimitive(PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);


				pDevice->SetRenderState(D3DRS_ZENABLE, true);

				if(ChamsColor2)
					pDevice->SetRenderState(D3DRS_AMBIENT, dwLightCur2);
				pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVDESTCOLOR);
				//pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_INVSRCALPHA);
				pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_SOLID);
			}break;
			
		case 6: // cube
			if(MyStride == PLAYER || MyStride == WEAPON){ 
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_SOLID);
				if(ChamsColor1)
					pDevice->SetTexture(NULL, Cur1);
				pDevice->SetRenderState(D3DRS_ZENABLE,false); 
					pDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT); 
				var = false;
				pDevice->DrawIndexedPrimitive(PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
				pDevice->SetRenderState(D3DRS_ZENABLE, true);
				if(ChamsColor2)
					pDevice->SetTexture(NULL, Cur2);
				pDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT); 
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_SOLID);
			}break;

		}var = true;
		switch(ColoredThings){ // |Walls|Ground|Weapons|Vehivles
		case 0: break;
		case 1: if( MyStride == WALLS ) if(ColoredThingsColors)pDevice->SetTexture( NULL, ThingsColor ); break;
		case 2: if( MyStride == GROUND ) if(ColoredThingsColors)pDevice->SetTexture( NULL, ThingsColor ); break;
		case 3: if( MyStride == WEAPON ) if(ColoredThingsColors)pDevice->SetTexture( NULL, ThingsColor ); break;
		case 4: if( MyStride == VEHICLES ) if(ColoredThingsColors)pDevice->SetTexture( NULL, ThingsColor ); break;
		}

		if(Asus){
			pDevice->SetRenderState( D3DRS_SRCBLEND, 0x5 );
			pDevice->SetRenderState( D3DRS_DESTBLEND, 0x2 );
			pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
		}

		if(WireFrame){
			if(MyStride == PLAYER){
				pDevice->SetRenderState(D3DRS_ZENABLE,false); 
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_WIREFRAME);
				var = false;
				pDevice->DrawIndexedPrimitive(  PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
				pDevice->SetRenderState(D3DRS_ZENABLE, true);
				pDevice->SetRenderState(D3DRS_FILLMODE,  D3DFILL_WIREFRAME);
			}
		}var = true;

		if(Fog){
				pDevice->SetRenderState(D3DRS_FOGENABLE,  false);
		}

	}

	DIP_EPILOGUE_MACRO
}

DWORD WINAPI CheatThread( LPVOID lpParam )
{

	// *(DWORD*) (*(DWORD*)(0xc333 + 0xF2954) +0xAA9 ) = 50; 
	pMenu->SCREEN_WIDTH = GetSystemMetrics( SM_CXBORDER );
	pMenu->SCREEN_HEIGHT = GetSystemMetrics( SM_CYBORDER );

	static bool val = false;
	//static int scope_origin = *(int*)ADR_Scope;
	while(11-22+678){
		Sleep(50);

		switch(BorderColor){//Red|Blue|Green|Yellow|Black|White|Orange|Purple
			case 0: dcBorderColor = D3DCOLOR_ARGB(120,255,69,0); break;
			case 1: dcBorderColor = D3DCOLOR_ARGB(120,255,64,64); break;
			case 2: dcBorderColor = D3DCOLOR_ARGB(120,24,116,205); break;
			case 3: dcBorderColor = D3DCOLOR_ARGB(120,34,139,34); break;
			case 4: dcBorderColor = D3DCOLOR_ARGB(120,255,255,0); break;
			case 5: dcBorderColor = D3DCOLOR_ARGB(120, 0, 0, 0); break;
			case 6: dcBorderColor = D3DCOLOR_ARGB(120,255,255,255); break;
			case 7: dcBorderColor = D3DCOLOR_ARGB(120,255,140,0); break;
			case 8: dcBorderColor = D3DCOLOR_ARGB(120,148,0,211); break;
		}

		switch(BorderSize){
			case 0:  pMenu->MENU_BORDER_SIZE = 4; break; // default
			case 1:  pMenu->MENU_BORDER_SIZE = 5; break;
			case 2:  pMenu->MENU_BORDER_SIZE = 4; break;
			case 3:  pMenu->MENU_BORDER_SIZE = 3; break;
			case 4:  pMenu->MENU_BORDER_SIZE = 2; break;
			case 5:  pMenu->MENU_BORDER_SIZE = 1; break;
		}

		static DWORD bColor;
		switch(BodyTransparent){
			case 0: bColor = 80; break;// default
			case 1: bColor = 255;break;
			case 2: bColor = 255 * 0.9;break;
			case 3: bColor = 255 * 0.8;break;
			case 4: bColor = 255 * 0.7;break;
			case 5: bColor = 255 * 0.6;break;
			case 6: bColor = 255 * 0.5;break;
			case 7: bColor = 255 * 0.4;break;
			case 8: bColor = 255 * 0.3;break;
			case 9: bColor = 255 * 0.2;break;
			case 10: bColor = 255 * 0.1;break;
			case 11: bColor = 255 * 0.0;break;
			}

		switch(BodyColor){//Red|Blue|Green|Yellow|Black|White|Orange|Purple
			case 0: dcBodyColor = D3DCOLOR_ARGB(bColor,120,0,0); break;
			case 1: dcBodyColor = D3DCOLOR_ARGB(bColor,255,64,64); break;
			case 2: dcBodyColor = D3DCOLOR_ARGB(bColor,24,116,205); break;
			case 3: dcBodyColor = D3DCOLOR_ARGB(bColor,34,139,34); break;
			case 4: dcBodyColor = D3DCOLOR_ARGB(bColor,255,255,0); break;
			case 5: dcBodyColor = D3DCOLOR_ARGB(bColor, 0, 0, 0); break;
			case 6: dcBodyColor = D3DCOLOR_ARGB(bColor,255,255,255); break;
			case 7: dcBodyColor = D3DCOLOR_ARGB(bColor,255,140,0); break;
			case 8: dcBodyColor = D3DCOLOR_ARGB(bColor,148,0,211); break;
		}

		switch(ChamsColor1){ // dwLightCur1 = ;, dwLightCur2 = ;
			case 0: break;//
			case 1: Cur1 = Red; dwLightCur1 = D3DCOLOR_ARGB(90,255,64,64); break;
			case 2: Cur1 = Blue;dwLightCur1 = D3DCOLOR_ARGB(90,24,116,205); break;
			case 3: Cur1 = Green;dwLightCur1 =  D3DCOLOR_ARGB(90,34,139,34); break;
			case 4: Cur1 = Yellow;dwLightCur1 = D3DCOLOR_ARGB(90,255,255,0); break;
			case 5: Cur1 = Black;dwLightCur1 = D3DCOLOR_ARGB(90, 0, 0, 0); break;
			case 6: Cur1 = White;dwLightCur1 = D3DCOLOR_ARGB(90,255,255,255); break;
			case 7: Cur1 = Orange;dwLightCur1 = D3DCOLOR_ARGB(90,255,140,0); break;
			case 8: Cur1 = Purple;dwLightCur1 = D3DCOLOR_ARGB(90,148,0,211); break;
		}

		switch(ChamsColor2){
			case 0: break;//
			case 1: Cur2 = Red;dwLightCur2 = D3DCOLOR_ARGB(90,255,64,64); break;
			case 2: Cur2 = Blue;dwLightCur2 = D3DCOLOR_ARGB(90,24,116,205); break;
			case 3: Cur2 = Green;dwLightCur2 = D3DCOLOR_ARGB(90,34,139,34); break;
			case 4: Cur2 = Yellow;dwLightCur2 = D3DCOLOR_ARGB(90,255,255,0); break;
			case 5: Cur2 = Black;dwLightCur2 = D3DCOLOR_ARGB(90, 0, 0, 0); break;
			case 6: Cur2 = White;dwLightCur2 = D3DCOLOR_ARGB(90,255,255,255); break;
			case 7: Cur2 = Orange;dwLightCur2 = D3DCOLOR_ARGB(90,255,140,0); break;
			case 8: Cur2 = Purple;dwLightCur2 = D3DCOLOR_ARGB(90,148,0,211); break;
		}
		switch(ColoredThingsColors){// Red|Blue|Green|Yellow|Black|White|Orange|Purple
			case 1: ThingsColor = Red; break;
			case 2: ThingsColor = Blue; break;
			case 3: ThingsColor = Green; break;
			case 4: ThingsColor = Yellow; break;
			case 5: ThingsColor = Black; break;
			case 6: ThingsColor = White; break;
			case 7: ThingsColor = Orange; break;
			case 8: ThingsColor = Purple; break;
		}

		
	//		pMenu->AddItem("No Spread", false, &Spread,"Off|0%|10%|20%|30%|40%|50%|60%|70%|80%|90%|100%");
	//pMenu->AddItem("Speed", false, &Speed, "Off|1.0|1.2|1.5|1.7|2.0|5.0|10.0");
		//switch(Speed){
		//	float val;
		//	case 0: break;
		//	case 1: {val = 96.0f;}*(float*)0x007CB498 = val;break;
		//	case 2: {val = (1.20f * 96.0f);}*(float*)0x007CB498 = val;break;
		//	case 3: { val = (1.50f * 96.0f);}*(float*)0x007CB498 = val;break;
		//	case 4: { val = (1.70f * 96.0f);}*(float*)0x007CB498 = val;break;
		//	case 5: { val = (2.0f * 96.0f);}*(float*)0x007CB498 = val;break;
		//	case 6: {val = (5.0f * 96.0f);}*(float*)0x007CB498 = val;break;
		//	case 7: { val = (10.0f * 96.0f);}*(float*)0x007CB498 = val;break;
		//	
		//	//pTools->MemPatch( (PUCHAR)0x007CB498, (PUCHAR)&val, sizeof(float) );
		//}
		//switch(RollSpeed){
		//	float val;
		//	case 0: break;
		//	case 1: { val = 1.75f;}*(float*)ADR_Speedroll= val;break;
		//	case 2: { val = (1.20f * 1.75f);}*(float*)ADR_Speedroll= val;break;
		//	case 3: { val = (1.50f * 1.75f);}*(float*)ADR_Speedroll= val;break;
		//	case 4: { val = (1.70f * 1.75f);}*(float*)ADR_Speedroll= val;break;
		//	case 5: { val = (2.0f * 1.75f);}*(float*)ADR_Speedroll= val;break;
		//	case 6: { val = (5.0f * 1.75f);}*(float*)ADR_Speedroll= val;break;
		//	case 7: { val = (10.0f * 1.75f);}*(float*)ADR_Speedroll= val;break;
		//
		//}
		//switch(Spread){
		//	float val;
		//	case 0: break;
		//	case 1: { val = 0;}break;
		//	case 2:  val = ( 0.1f * (*(float*)0x008FC798) );*(float*)0x008FC798 = val;break;
		//	case 3:  val = (0.2f * (*(float*)0x008FC798));*(float*)0x008FC798 = val;break;
		//	case 4:  val = (0.3f * (*(float*)0x008FC798));*(float*)0x008FC798 = val;break;
		//	case 5: val = (0.4f * (*(float*)0x008FC798));*(float*)0x008FC798 = val;break;
		//	case 6: val = (0.5f * (*(float*)0x008FC798));*(float*)0x008FC798 = val;break;
		//	case 7:  val = (0.6f * (*(float*)0x008FC798));*(float*)0x008FC798 = val;break;
		//	case 8:  val = (0.7f * (*(float*)0x008FC798));*(float*)0x008FC798 = val;break;
		//	case 9: val = (0.8f * (*(float*)0x008FC798));*(float*)0x008FC798 = val;break;
		//	case 10:  val = (0.9f * (*(float*)0x008FC798));*(float*)0x008FC798 = val;break;
		//	case 11:  val = ( (*(float*)0x008FC798) );*(float*)0x008FC798 = val;break;

		//}

		//if(Fahr){
		//	int val = 5000000;
		//	*(int*)ADR_FastAmmo = val;
		//	*(int*)ADR_FastRepair = val;
		//	*(int*)ADR_FastHealth = val;
		//	*(int*)ADR_FastFlag = val;

		//}
		//if(Scope){
		//	
		//	if(GetAsyncKeyState(VK_RBUTTON)&1){
		//		val = !val;
		//	}
		//	if(val){
		//		*(int*)ADR_Scope = 1;
		//	}else *(int*)ADR_Scope = -1;
		//}
		//if(Spawn){
		//	long val = 0;
		//	*(long*)ADR_NoSpawn1 = val;
		//	*(long*)ADR_NoSpawn2 = val;

		//}
		//if(CQCSpawn){
		//	DWORD val = 0;
		//	//pTools->MemPatch((PUCHAR)ADR_CQCSpawn,(PUCHAR)&val, sizeof(DWORD));
		//	*(DWORD*)ADR_CQCSpawn = 0;
		//}

		
	}
	return 1;
}

DWORD WINAPI MainThread( LPVOID lpParam )
{
	unsigned long** ulDevicePtr = pTools->FindDevice();
	unsigned long ** VTable ;
	*(unsigned long **)&VTable = *(unsigned long **)ulDevicePtr;
	Items();
	HMODULE mod = 0;
	while(!mod){
		 mod = pGetModuleHandle("d3d9.dll");
		 pSleep(50);
	}mod = 0;
	//MessageBoxA(0,"2",0,0);
	while((true)){ 
		pSleep(300);
		if(*(BYTE*)(VTable[42] /*+ 48*/) != 0xEB){
			pTools->MemXorJmp(FREE_MEM(0), (unsigned long)hkEndScene);
			oEndScene = (pEndScene)pTools->MemHotPatch((unsigned long)VTable[42], FREE_MEM(0), false);
		}
		 if(*(BYTE*)(VTable[16] /*+ 46*/) != 0xEB){
			
			pTools->MemXorJmp(FREE_MEM(2), (unsigned long)hkReset); 
			oReset = (pReset)pTools->MemHotPatch((unsigned long)VTable[16], FREE_MEM(2), false);
		}
		//else if(*(BYTE*)(VTable[82] + 0x23) != 0xEB){
		//	pTools->MemXorJmp(FREE_MEM(6), (unsigned long)hkDrawIndexedPrimitive);
		//	oDrawIndexedPrimitive = (pDrawIndexedPrimitive)pTools->MemHotPatch((unsigned long)VTable[82], FREE_MEM(6), true );
		 if(*(BYTE*)(VTable[82] + 48) != 0xEB){
			 
			pTools->MemXorJmp(FREE_MEM(4), (unsigned long)hkDrawIndexedPrimitive);
			oDrawIndexedPrimitive = (pDrawIndexedPrimitive)pTools->MemHotPatch((unsigned long)VTable[82], FREE_MEM(4), true );
		}
	}

	return true;
}

VOID WINAPI ApiCalling() 
{
	unsigned long MsgBoxAddr = pTools->FindAPI("user32.dll", "MessageBoxA");
	MsgBox = (MyMessageboxA (__stdcall *))MsgBoxAddr;

	unsigned long SleepAddr = pTools->FindAPI("kernel32.dll", "Sleep");
	pSleep = (MySleep (__stdcall *))SleepAddr;

	unsigned long GetModuleFileNameAddr = pTools->FindAPI("kernel32.dll", "GetModuleFileNameA");
	pGetModuleFileName = (MyGetModuleFileName (__stdcall *))GetModuleFileNameAddr;

	unsigned long CreateThreadAddr = pTools->FindAPI("kernel32.dll", "CreateThread");
	pCreateThread = (MyCreateThread (__stdcall *))CreateThreadAddr;

	unsigned long LoadLibraryAddr = pTools->FindAPI("kernel32.dll", "LoadLibraryA");
	pLoadLibrary = (MyLoadLibrary (__stdcall *))LoadLibraryAddr;

	unsigned long VirtualProtectAddr = pTools->FindAPI("kernel32.dll", "VirtualProtect");
	pVirtualProtect = (MyVirtualProtect (__stdcall *))VirtualProtectAddr;

	unsigned long GetModuleHandleAddr = pTools->FindAPI("kernel32.dll", "GetModuleHandleA");
	pGetModuleHandle = (MyGetModuleHandle (__stdcall *))GetModuleHandleAddr;
}

BOOL WINAPI DllMain( HMODULE hModule, DWORD  dwCallType, LPVOID lpReserved )
{
	switch( dwCallType )
	{
		case DLL_PROCESS_ATTACH:
			ApiCalling();
			
			GetModuleFileNameA(hModule, (LPSTR)pTools->dllfn, 300);
			CreateThread(NULL, NULL, MainThread, NULL, NULL, NULL);
			CreateThread(NULL, NULL, CheatThread, NULL, NULL, NULL);
		break;

		case DLL_PROCESS_DETACH:
		break;
	}
	return true;
}